package cn.itcast.cxf.rs.client;

import cn.itcast.cxf.domain.User;
import org.apache.cxf.jaxrs.client.WebClient;

import javax.ws.rs.core.MediaType;
import java.util.Collection;

/**
 * Created by Think on 2017/9/19.
 */
public class RS_Client {
    public static void main(String[] args) {
        //新增
        System.out.println("*************新增**************");
        User user = new User();
        user.setId(3);
        user.setUsername("小美");
        user.setCity("深圳");
        WebClient.create("http://localhost:9999/userService")
                .path("/user")//path可以省略,写到上面路径上
                .type(MediaType.APPLICATION_JSON)
                .post(user);
        System.out.println("*************修改**************");
        //修改
        WebClient.create("http://localhost:9999/userService")
                .path("/user")//path可以省略,写到上面路径上
                .type(MediaType.APPLICATION_JSON)
                .put(user);
        System.out.println("*************查询id**************");
        //根据id查询
        User user1 = WebClient.create("http://localhost:9999/userService")
                .path("/user/1")//path可以省略,写到上面路径上
                .accept(MediaType.APPLICATION_XML)
                .get(User.class);
        System.out.println(user1);
        System.out.println("*************删除**************");
        //删除
        WebClient.create("http://localhost:9999/userService")
                .path("/user/1")//path可以省略,写到上面路径上
                .type(MediaType.APPLICATION_XML)
                .delete();
        System.out.println("*************查询所有**************");
        //查询所有
        Collection<? extends User> users = WebClient.create("http://localhost:9999/userService")
                .path("/user")//path可以省略,写到上面路径上
                .accept(MediaType.APPLICATION_XML)
                .getCollection(User.class);
        System.out.println(users);

    }
}
